#include <REGX52.H>
#include "duoji.h"

sbit pwm_SG90 =P0^7;

unsigned char counter = 0;

unsigned char SG90 = 0;

void Timer1_Init()		//100微秒@11.0592MHz

{

	TMOD &= 0x0F;			//设置定时器模式
	TMOD |= 0x10;			//设置定时器模式
	TL1 = 0xA4;				//设置定时初始值
	TH1 = 0xFF;				//设置定时初始值
	TF1 = 0;				//清除TF1标志
	TR1 = 1;				//定时器1开始计时
	
	ET1=1;
	EA=1;
	PT1=1;
}


void duoji() interrupt 3
{
	TL1 = 0xA4;				//设置定时初始值
	TH1 = 0xFF;				//设置定时初始值
	
	counter++;
	counter %=200;
	
	if(counter<=SG90)
	{pwm_SG90=1;}
	else
	{pwm_SG90=0;}
}


void control(unsigned char control_SG90)
{
	switch(control_SG90)
	{
		case 1:SG90 = 5;break;
		case 2:SG90 = 10;break;
		case 3:SG90 = 15;break;
		case 4:SG90 = 20;break;
		case 5:SG90 = 25;break;

	}
}




